

#include <stdio.h>
#include "Nano100Series.h"
#include "GPIO_IIC.h"
#include "hdmi2mipi.h"
#include "hdmi_regset.h"
#include "common.h"

uint8_t buffer[20];
//static uint8_t status_3d=1;

void delay_ms(int ms)
{
	while(ms--)
		{
			CLK_SysTickDelay(1000);
			// handle USB event
			UsbTransferHandleEvent();

			// update sensor
			if (Timer1IsTrigger()) {
				Timer1ResetFlag();
				UsbTransferHandleSensorUpdate();
			}
		}

}

void wait_ms(int ms) {
	while(ms--) {
		CLK_SysTickDelay(1000);
	}
}

void hdmi_softrst()
{

	
	buffer[0]=00, buffer[1]=04, buffer[2]=04, buffer[3]=00; //</i2c_write>
	i2c_write(SLAVE_ADDRESS, buffer,4);
	buffer[0]=00, buffer[1]=02, buffer[2]=01, buffer[3]=0x3F; //</i2c_write>
	i2c_write(SLAVE_ADDRESS, buffer,4);
	buffer[0]=00, buffer[1]=02, buffer[2]=00, buffer[3]=00; //</i2c_write>
	i2c_write(SLAVE_ADDRESS, buffer,4);
	buffer[0]=00, buffer[1]=06, buffer[2]=0x08, buffer[3]=00; //</i2c_write>
	i2c_write(SLAVE_ADDRESS, buffer,4);


}

void hdmi_audio_disable()
{
	PA14 = 0;
	wait_ms(1);
}

void hdmi_audio_enable()
{
	PA14 = 1;
}

//#define p3840_
void hdmi_settxtiming()
{
//	// <!-- DSI-TX0 Transition Timing -->
//	buffer[0]=0x01, buffer[1]=0x08, buffer[2]=0x01, buffer[3]=0x00, buffer[4]=0x00, buffer[5]=0x00;  //</i2c_write> 	
//	i2c_write(SLAVE_ADDRESS, buffer,6);
//	buffer[0]=0x01, buffer[1]=0x0C, buffer[2]=0x01, buffer[3]=0x00, buffer[4]=0x00, buffer[5]=0x00;  //</i2c_write> 	
//	i2c_write(SLAVE_ADDRESS, buffer,6);
//	buffer[0]=0x02, buffer[1]=0xA0, buffer[2]=0x01, buffer[3]=0x00, buffer[4]=0x00, buffer[5]=0x00;  //</i2c_write> 
//	i2c_write(SLAVE_ADDRESS, buffer,6);
//	buffer[0]=0x02, buffer[1]=0xAC, buffer[2]=0xB9, buffer[3]=0x90, buffer[4]=0x00, buffer[5]=0x00;  //</i2c_write> 
//	i2c_write(SLAVE_ADDRESS, buffer,6);
//	
//	CLK_SysTickDelay(1000);	
	
	write_reg_32(SLAVE_ADDRESS,0x0108,	0x000000001);
	write_reg_32(SLAVE_ADDRESS,0x010C,	0x000000001);
	write_reg_32(SLAVE_ADDRESS,0x02A0,	0x000000001);
	#if 1
	#ifdef p3840_
	write_reg_32(SLAVE_ADDRESS,0x02AC,	0x0000090BD);
	#else
	write_reg_32(SLAVE_ADDRESS,0x02AC,	0x0000090B9);
	#endif
	#else
	
	#endif
	CLK_SysTickDelay(2000);	
	//write_reg_32(SLAVE_ADDRESS,0x1000,	0x0 	   );
	write_reg_32(SLAVE_ADDRESS,0x02A0,	0x000000003);
	write_reg_32(SLAVE_ADDRESS,0x0118,	0x000000014);
	write_reg_32(SLAVE_ADDRESS,0x0120,	0x000001770);
	write_reg_32(SLAVE_ADDRESS,0x0124,	0x000000000);
	write_reg_32(SLAVE_ADDRESS,0x0128,	0x000000101);
	//write_reg_32(SLAVE_ADDRESS,0x012C,	0x000000000);
	write_reg_32(SLAVE_ADDRESS,0x0130,	0x000010000);
	write_reg_32(SLAVE_ADDRESS,0x0134,	0x000005000);
	write_reg_32(SLAVE_ADDRESS,0x0138,	0x000010000);
	write_reg_32(SLAVE_ADDRESS,0x013C,	0x000010000);
	write_reg_32(SLAVE_ADDRESS,0x0140,	0x000010000);
	write_reg_32(SLAVE_ADDRESS,0x0144,	0x000010000);
	write_reg_32(SLAVE_ADDRESS,0x0148,	0x000001000);
	write_reg_32(SLAVE_ADDRESS,0x014C,	0x000010000);
	write_reg_32(SLAVE_ADDRESS,0x0150,	0x000000161);
	write_reg_32(SLAVE_ADDRESS,0x0154,	0x000000001);
	write_reg_32(SLAVE_ADDRESS,0x0158,	0x0000000C8);
	//write_reg_32(SLAVE_ADDRESS,0x0164,	0x000000014);
	write_reg_32(SLAVE_ADDRESS,0x0168,	0x00000002A);
	#if 1
	#ifdef p3840_
	write_reg_32(SLAVE_ADDRESS,0x0170,	0x000000677);
	#else
	write_reg_32(SLAVE_ADDRESS,0x0170,	0x000000654);
	#endif
	#else
	write_reg_32(SLAVE_ADDRESS,0x0170,	0x00000063E);
	#endif
	
	//write_reg_32(SLAVE_ADDRESS,0x0178,	0x000000001);
	write_reg_32(SLAVE_ADDRESS,0x017C,	0x000000081);
	write_reg_32(SLAVE_ADDRESS,0x018C,	0x000000001);
	#if 1
	#ifdef p3840_
	write_reg_32(SLAVE_ADDRESS,0x0190,	0x00000024e);
	#else
	write_reg_32(SLAVE_ADDRESS,0x0190,	0x000000104);
	#endif
	#else
	write_reg_32(SLAVE_ADDRESS,0x0190,	0x00000018d);
	#endif
	write_reg_32(SLAVE_ADDRESS,0x01A4,	0x000000000);
	//write_reg_32(SLAVE_ADDRESS,0x01AC,	0x000000000);
	write_reg_32(SLAVE_ADDRESS,0x01C0,	0x000000015);
	//write_reg_32(SLAVE_ADDRESS,0x020C,	0x000000000);
	write_reg_32(SLAVE_ADDRESS,0x0214,	0x000000000);
	write_reg_32(SLAVE_ADDRESS,0x021C,	0x000000080);
	write_reg_32(SLAVE_ADDRESS,0x0224,	0x000000000);
	//write_reg_32(SLAVE_ADDRESS,0x0240,	0x000000000);
	write_reg_32(SLAVE_ADDRESS,0x0254,	0x000000006);
	write_reg_32(SLAVE_ADDRESS,0x0258,	0x000240204);
	write_reg_32(SLAVE_ADDRESS,0x025C,	0x0000D0009);
	write_reg_32(SLAVE_ADDRESS,0x0260,	0x000140007);
	write_reg_32(SLAVE_ADDRESS,0x0264,	0x000004268);
	write_reg_32(SLAVE_ADDRESS,0x0268,	0x00000000F);
	write_reg_32(SLAVE_ADDRESS,0x026C,	0x0000D0008);
	write_reg_32(SLAVE_ADDRESS,0x0270,	0x000000020);
	write_reg_32(SLAVE_ADDRESS,0x0274,	0x00000001F);
	write_reg_32(SLAVE_ADDRESS,0x0278,	0x000060005);
	write_reg_32(SLAVE_ADDRESS,0x027C,	0x000000002);
	//write_reg_32(SLAVE_ADDRESS,0x0288,	0x0000002AA);
	write_reg_32(SLAVE_ADDRESS,0x011C,	0x000000001);
	//write_reg_32(SLAVE_ADDRESS,0x	   , 00x		 );
	write_reg_32(SLAVE_ADDRESS,0x0308,	0x000000001);
	write_reg_32(SLAVE_ADDRESS,0x030C,	0x000000001);
	write_reg_32(SLAVE_ADDRESS,0x04A0,	0x000000001);
	//write_reg_32(SLAVE_ADDRESS,0x04AC,	0x0000090B9);
	#if 1
	#ifdef p3840_
	write_reg_32(SLAVE_ADDRESS,0x04AC,	0x0000090BD);
	#else
	write_reg_32(SLAVE_ADDRESS,0x04AC,	0x0000090B9);
	#endif
	#else
	write_reg_32(SLAVE_ADDRESS,0x04AC,	0x0000090B9);
	#endif
	CLK_SysTickDelay(2000);	
	write_reg_32(SLAVE_ADDRESS,0x04A0,	0x000000003);
	write_reg_32(SLAVE_ADDRESS,0x0318,	0x000000014);
	write_reg_32(SLAVE_ADDRESS,0x0320,	0x000001770);
	write_reg_32(SLAVE_ADDRESS,0x0324,	0x000000000);
	write_reg_32(SLAVE_ADDRESS,0x0328,	0x000000101);
	//write_reg_32(SLAVE_ADDRESS,0x032C,	0x000000004);
	write_reg_32(SLAVE_ADDRESS,0x0330,	0x000010000);
	write_reg_32(SLAVE_ADDRESS,0x0334,	0x000005000);
	write_reg_32(SLAVE_ADDRESS,0x0338,	0x000010000);
	write_reg_32(SLAVE_ADDRESS,0x033C,	0x000010000);
	write_reg_32(SLAVE_ADDRESS,0x0340,	0x000010000);
	write_reg_32(SLAVE_ADDRESS,0x0344,	0x000010000);
	write_reg_32(SLAVE_ADDRESS,0x0348,	0x000001000);
	write_reg_32(SLAVE_ADDRESS,0x034C,	0x000010000);
	write_reg_32(SLAVE_ADDRESS,0x0350,	0x000000161);
	write_reg_32(SLAVE_ADDRESS,0x0354,	0x000000001);
	write_reg_32(SLAVE_ADDRESS,0x0358,	0x0000000C8);
	//write_reg_32(SLAVE_ADDRESS,0x0364,	0x000000015);
	write_reg_32(SLAVE_ADDRESS,0x0368,	0x00000002A);
	//write_reg_32(SLAVE_ADDRESS,0x0370,	0x000000654);
	#if 1
#ifdef p3840_
	write_reg_32(SLAVE_ADDRESS,0x0370,	0x000000677);
#else
	write_reg_32(SLAVE_ADDRESS,0x0370,	0x000000654);
#endif
	#else
	write_reg_32(SLAVE_ADDRESS,0x0370,	0x00000063e);
	#endif
	//write_reg_32(SLAVE_ADDRESS,0x0378,	0x000000001);
	write_reg_32(SLAVE_ADDRESS,0x037C,	0x000000081);
	write_reg_32(SLAVE_ADDRESS,0x038C,	0x000000001);
	//write_reg_32(SLAVE_ADDRESS,0x0390,	0x000000242);
#if 1
#ifdef p3840_
	write_reg_32(SLAVE_ADDRESS,0x0390,	0x00000024e);
#else
	write_reg_32(SLAVE_ADDRESS,0x0390,	0x000000104);
#endif
#else
	write_reg_32(SLAVE_ADDRESS,0x0390,	0x00000018D);
#endif
	write_reg_32(SLAVE_ADDRESS,0x03A4,	0x000000000);
	//write_reg_32(SLAVE_ADDRESS,0x03AC,	0x000000000);
	write_reg_32(SLAVE_ADDRESS,0x03C0,	0x000000015);
	//write_reg_32(SLAVE_ADDRESS,0x040C,	0x000000000);
	write_reg_32(SLAVE_ADDRESS,0x0414,	0x000000000);
	write_reg_32(SLAVE_ADDRESS,0x041C,	0x000000080);
	write_reg_32(SLAVE_ADDRESS,0x0424,	0x000000000);
	//write_reg_32(SLAVE_ADDRESS,0x0440,	0x000000000);
	write_reg_32(SLAVE_ADDRESS,0x0454,	0x000000006);
	write_reg_32(SLAVE_ADDRESS,0x0458,	0x000240204);
	write_reg_32(SLAVE_ADDRESS,0x045C,	0x0000D0009);
	write_reg_32(SLAVE_ADDRESS,0x0460,	0x000140007);
	write_reg_32(SLAVE_ADDRESS,0x0464,	0x000004268);
	write_reg_32(SLAVE_ADDRESS,0x0468,	0x00000000F);
	write_reg_32(SLAVE_ADDRESS,0x046C,	0x0000D0008);
	write_reg_32(SLAVE_ADDRESS,0x0470,	0x000000020);
	write_reg_32(SLAVE_ADDRESS,0x0474,	0x00000001F);
	write_reg_32(SLAVE_ADDRESS,0x0478,	0x000060005);
	write_reg_32(SLAVE_ADDRESS,0x047C,	0x000000002);
	//write_reg_32(SLAVE_ADDRESS,0x0488,	0x000000000);
	write_reg_32(SLAVE_ADDRESS,0x031C,	0x000000001);
	

}




void hdmi_command_trans_init()
{
	
	//<!-- Command Transmission Before Video Start -->																									  
	buffer[0]=0x05,buffer[1]=0x00, buffer[2]=0x04, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write> 									  
	buffer[0]=0x01,buffer[1]=0x10, buffer[2]=0x10, buffer[3]=0x00, buffer[4]=0x00, buffer[5]=00,i2c_write(SLAVE_ADDRESS,buffer,6);	//</i2c_write>		  
	buffer[0]=0x03,buffer[1]=0x10, buffer[2]=0x10, buffer[3]=0x00, buffer[4]=0x00, buffer[5]=00,i2c_write(SLAVE_ADDRESS,buffer,6); //</i2c_write>		  
						  

}

void split_lcd_half(uint8_t On)
{
	if(On)
		{
			//split on
			buffer[0]=0x50, buffer[1]=0x00, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
			buffer[0]=0x50, buffer[1]=0x0C, buffer[2]=0x00, buffer[3]=0x80,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
			//buffer[0]=0x50, buffer[1]=0x0e, buffer[2]=0x7f, buffer[3]=0x07,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
			buffer[0]=0x50, buffer[1]=0x80, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4);
			//buffer[0]=0x50, buffer[1]=0x8c, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4);
			//buffer[0]=0x50, buffer[1]=0x8e, buffer[2]=0x7f, buffer[3]=0x07,i2c_write(SLAVE_ADDRESS,buffer,4);
		}
	else
		{
			buffer[0]=0x50, buffer[1]=0x00, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
			buffer[0]=0x50, buffer[1]=0x0C, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
			buffer[0]=0x50, buffer[1]=0x0e, buffer[2]=0x7f, buffer[3]=0x07,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
			buffer[0]=0x50, buffer[1]=0x80, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4);
			buffer[0]=0x50, buffer[1]=0x8c, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4);
			buffer[0]=0x50, buffer[1]=0x8e, buffer[2]=0x7f, buffer[3]=0x07,i2c_write(SLAVE_ADDRESS,buffer,4);
		}
}


void split_lcd(uint8_t On)
{
	if(On)
		{
			//split on
			buffer[0]=0x50, buffer[1]=0x00, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
			buffer[0]=0x50, buffer[1]=0x0C, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
			buffer[0]=0x50, buffer[1]=0x0e, buffer[2]=0x7f, buffer[3]=0x07,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
			buffer[0]=0x50, buffer[1]=0x80, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4);
			buffer[0]=0x50, buffer[1]=0x8c, buffer[2]=0x85, buffer[3]=0x07,i2c_write(SLAVE_ADDRESS,buffer,4);
			buffer[0]=0x50, buffer[1]=0x8e, buffer[2]=0xff, buffer[3]=0x0e,i2c_write(SLAVE_ADDRESS,buffer,4);
			
			buffer[0]=0x50, buffer[1]=0x8a, buffer[2]=0x05, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
			buffer[0]=0x50, buffer[1]=0x90, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4);
			buffer[0]=0x50, buffer[1]=0x92, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4);
			buffer[0]=0x50, buffer[1]=0x94, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4);
		}
	else
		{
			buffer[0]=0x50, buffer[1]=0x00, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
			buffer[0]=0x50, buffer[1]=0x0C, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
			buffer[0]=0x50, buffer[1]=0x0e, buffer[2]=0x7f, buffer[3]=0x07,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
			buffer[0]=0x50, buffer[1]=0x80, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4);
			buffer[0]=0x50, buffer[1]=0x8c, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4);
			buffer[0]=0x50, buffer[1]=0x8e, buffer[2]=0x7f, buffer[3]=0x07,i2c_write(SLAVE_ADDRESS,buffer,4);
		}
}

void lcd_init()
{

//	//<!-- LCD Initialization -->																														  
//	//<!-- Soft Reset -->																																  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x05, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x01, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	//<sleep ms="5" />	
//	CLK_SysTickDelay(5000);
//	//<!-- Set Pixel Format --> 																														  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x15, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x3A, buffer[3]=0x77,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	//<sleep ms="1" />
//	CLK_SysTickDelay(1000);
//	//<!-- Set Column Address -->																														  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x39, buffer[3]=0x80,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x05, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x2A, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x00, buffer[3]=0x04,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0xFF, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4);//</i2c_write> 									  
//	//<sleep ms="1" />	
//	CLK_SysTickDelay(1000);
//	//<!-- Set Page Address --> 																														  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x39, buffer[3]=0x80,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x05, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x2B, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x00, buffer[3]=0x06,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x3F, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	//<sleep ms="1" />
//	CLK_SysTickDelay(1000);
//	//<!-- Set Tear On -->																																  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x15, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x35, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	//<sleep ms="1" />	
//	CLK_SysTickDelay(1000);
//	//<!-- Set Tear Scanline -->																														  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x39, buffer[3]=0x80,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x03, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x44, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	//<sleep ms="1" />	
//	CLK_SysTickDelay(1000);
//	//<!-- Write Display Brightness --> 																												  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x15, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x51, buffer[3]=0xFF,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	//<sleep ms="1" />
//	CLK_SysTickDelay(1000);
//	//<!-- Write Control Display -->																													  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x15, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x53, buffer[3]=0x24,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	//<sleep ms="1" />	
//	CLK_SysTickDelay(1000);
//	//<!-- Adaptive Brightness Control -->																												  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x15, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x55, buffer[3]=0x01,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	//<sleep ms="1" />	
//	CLK_SysTickDelay(1000);
//	//<!-- Exit Sleep -->																																  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x05, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x11, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	//<sleep ms="120" />		
//	CLK_SysTickDelay(120000);
//	//<!-- MCAP --> 																																	  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x23, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0xB0, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	//<sleep ms="1" />	
//	CLK_SysTickDelay(1000);
//	//<!-- Backlight Control 4 -->																														  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x29, buffer[3]=0x80,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x14, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0xCE, buffer[3]=0x7D,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x40, buffer[3]=0x48,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x56, buffer[3]=0x67,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x78, buffer[3]=0x88,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x98, buffer[3]=0xA7,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0xB5, buffer[3]=0xC3,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0xD1, buffer[3]=0xDE,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0xE9, buffer[3]=0xF2,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0xFA, buffer[3]=0xFF,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
//	buffer[0]=0x05, buffer[1]=0x04, buffer[2]=0x04, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
	//<!-- Split Control -->				
	//<!-- HDMI PHY --> 																																  
	buffer[0]=0x84, buffer[1]=0x10, buffer[2]=0x03,i2c_write(SLAVE_ADDRESS,buffer,3); //,</i2c_write>										  
	buffer[0]=0x84, buffer[1]=0x13, buffer[2]=0x3F,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>										  
	buffer[0]=0x84, buffer[1]=0x20, buffer[2]=0x07,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>										  
	buffer[0]=0x84, buffer[1]=0xF0, buffer[2]=0x31,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>	 noise									  
	buffer[0]=0x84, buffer[1]=0xF4, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>										  
	//<!-- HDMI Clock -->																																  
	buffer[0]=0x85, buffer[1]=0x40, buffer[2]=0xC0, buffer[3]=0x12,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
	buffer[0]=0x86, buffer[1]=0x30, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3);//,</i2c_write>										  
	buffer[0]=0x86, buffer[1]=0x31, buffer[2]=0x53, buffer[3]=0x07,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
	buffer[0]=0x86, buffer[1]=0x70, buffer[2]=0x02, i2c_write(SLAVE_ADDRESS,buffer,3);//,</i2c_write>										  
	buffer[0]=0x8A, buffer[1]=0x0C, buffer[2]=0xC0, buffer[3]=0x12,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
	//<!-- HDMI Interrupt Mask, Clear -->																												  
	buffer[0]=0x85, buffer[1]=0x0B, buffer[2]=0xFF, i2c_write(SLAVE_ADDRESS,buffer,3);//,</i2c_write>										  
	buffer[0]=0x85, buffer[1]=0x1B, buffer[2]=0xFD, i2c_write(SLAVE_ADDRESS,buffer,3);//,</i2c_write>										  
	//<!-- Interrupt Control (TOP level) -->																											  
	buffer[0]=0x00, buffer[1]=0x14, buffer[2]=0xBF, buffer[3]=0x0F,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
	buffer[0]=0x00, buffer[1]=0x16, buffer[2]=0xBF, buffer[3]=0x0D,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>			


}

void HDMI_CheckSig()
{
	static uint8_t buf[20];

	buffer[0]=0x85, buffer[1]=0x40, buffer[2]=0xC0, buffer[3]=0x12,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>									  
							  
	buffer[0]=0x8A, buffer[1]=0x0C, buffer[2]=0xC0, buffer[3]=0x12,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>		

	buffer[0]=0x85, buffer[1]=0x93, buffer[2]=0x33, i2c_write(SLAVE_ADDRESS,buffer,3);//,</i2c_write>	
	CLK_SysTickDelay(30000);

	i2c_read(SLAVE_ADDRESS,0x8405,&buffer[0],1);
	i2c_read(SLAVE_ADDRESS,0x8406,&buffer[1],1);
	i2c_read(SLAVE_ADDRESS,0x858e,&buffer[2],1);
	i2c_read(SLAVE_ADDRESS,0x858f,&buffer[3],1);
	i2c_read(SLAVE_ADDRESS,0x8580,&buffer[4],1);
	i2c_read(SLAVE_ADDRESS,0x8581,&buffer[5],1);
	i2c_read(SLAVE_ADDRESS,0x8582,&buffer[6],1);
	i2c_read(SLAVE_ADDRESS,0x8583,&buffer[7],1);
	i2c_read(SLAVE_ADDRESS,0x8590,&buffer[8],1);
	i2c_read(SLAVE_ADDRESS,0x8591,&buffer[9],1);


	i2c_read(SLAVE_ADDRESS,0x8584,&buffer[10],1);
	i2c_read(SLAVE_ADDRESS,0x8585,&buffer[11],1);
	i2c_read(SLAVE_ADDRESS,0x8586,&buffer[12],1);
	i2c_read(SLAVE_ADDRESS,0x8587,&buffer[13],1);
	i2c_read(SLAVE_ADDRESS,0x858c,&buffer[14],1);
	i2c_read(SLAVE_ADDRESS,0x858d,&buffer[15],1);
	i2c_read(SLAVE_ADDRESS,0x8526,&buffer[16],1);

	CLK_SysTickDelay(30000);
	
}

void HDMI_init(void)
{
	uint8_t buf[2];
//	PD7=0;	
//	PD13=1;
//	CLK_SysTickDelay(30000);	
//	PD7=1;	
//	PD13=0;
	//CLK_SysTickDelay(30000);
	is_video_on = 0;
	hdmi_softrst();
	oled_init();
	hdmi_settxtiming();
	CLK_SysTickDelay(1000);
	hdmi_command_trans_init();
	
	lcd_init();
	lvds_init_all_1080();
	
	buffer[0]=0x85, buffer[1]=0xE0, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x85, buffer[1]=0xE3, buffer[2]=0x00, buffer[3]=0x01,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>	
	if(status_3d == MODE_3D_FULL)
		{
			i2c_write(SLAVE_ADDRESS,(uint8_t *)edid_3840,258);
			split_lcd(TRUE);	
		}
	else if(status_3d == MODE_3D_HALF)
		{
			i2c_write(SLAVE_ADDRESS,(uint8_t *)edid_1080,258);
			split_lcd(TRUE);	
			mipi2lvds_1080_single(1,0x1f);
			mipi2lvds_1080_single(2,0x1f);
		}
	else
		{
			i2c_write(SLAVE_ADDRESS,(uint8_t *)edid_1080,258);
			split_lcd(FALSE);	
		}
	
	hdmi_hdcpsetting();
	
	
	if(hdmi_wait_hdmisync())
		{
			//hdmi_settxtiming();
			//hdmi_video_start();
		}

	//HDMI_CheckSig();
	
	//hdmi_video_stop();
	delay_ms(1000);
	hdmi_video_start();
	//CLK_SysTickDelay(10000);
	oled_start();



}

void hdmi_monitor()
{
	static char status=1;

	
	//buffer[0]=0x85, buffer[1]=0x20,i2c_write(SLAVE_ADDRESS,buffer,2);	//</i2c_write>	
	i2c_read(SLAVE_ADDRESS,0x8520,buffer,1);
	if(buffer[0]&0x80)
		{
			//return 1;
		}
	//<i2c_read addr="0x0F" count="1" radix="16" /> 																	  
	//<!-- Sequence: Check bit7 of 8x8520 -->																			  
	buffer[0]=0x85, buffer[1]=0x0B, buffer[2]=0xFF,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					  
	buffer[0]=0x00, buffer[1]=0x14, buffer[2]=0xBF, buffer[3]=0x0F,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>	  
	//<!-- By Polling -->																								  
	//buffer[0]=0x85, buffer[1]=0x20,i2c_write(SLAVE_ADDRESS,buffer,2);	//</i2c_write>		

	i2c_read(SLAVE_ADDRESS,0x8520,buffer,1);
	if(buffer[0]&0x80)
		{
			return;
		}
	is_video_on = 0;
	//PD10=1;
	CLK_SysTickDelay(10000);
	hdmi_video_stop();
	oled_stop();
	//PD7=0;	
	PC6=1;	
	PA9=0;
	CLK_SysTickDelay(30000);	
	//PD7=1;	
	PC6=0;	
	PA9=1;

	HDMI_init();
	is_video_on = 1;
	hdmi_audio_enable();
}



#if 1
void Switch_3D(uint8_t status)
{
	hdmi_audio_disable();
	
	oled_stop();
	PC6=1;	
	PA9=0;
	CLK_SysTickDelay(300);	
	PC6=0;	
	PA9=1;	//hdmi reset should be 0
	
	CLK_SysTickDelay(300);	
	hdmi_softrst();
	oled_init();
	//CLK_SysTickDelay(30000);	
	hdmi_settxtiming();
	CLK_SysTickDelay(1000);
	hdmi_command_trans_init();
	lcd_init();
	lvds_init_all_1080();
	buffer[0]=0x85, buffer[1]=0xE0, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x85, buffer[1]=0xE3, buffer[2]=0x00, buffer[3]=0x01,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>	
	if(status==0)
		{
			i2c_write(SLAVE_ADDRESS,(uint8_t *)edid_1080,258);
			//status_3d=1;
			split_lcd(FALSE);
			
			
		}
	else
		{
			i2c_write(SLAVE_ADDRESS,(uint8_t *)edid_3840,258);
			split_lcd(TRUE);
			//status_3d=0;
			//lvds_init_all_3840();
		}
	
	
	
	hdmi_hdcpsetting();
	
	
	//TI_init();
	
	if(hdmi_wait_hdmisync())
		{
			//CLK_SysTickDelay(30000);
			//hdmi_video_start();
		}	
	//hdmi_video_stop();
	CLK_SysTickDelay(1000);
	hdmi_video_start();
	//CLK_SysTickDelay(10000);
	//CLK_SysTickDelay(10000);
	oled_start();
	wait_ms(10);
	hdmi_audio_enable();
}



void Switch_3D_fast(uint8_t status)
{

	
		
		oled_stop();
		hdmi_video_stop();
		
		if(status==0)
			{
				//i2c_write(SLAVE_ADDRESS,(uint8_t *)edid_1080,258);
				//status_3d=1;
				mipi2lvds_1080_dual(1,0x1f);
				mipi2lvds_1080_dual(2,0x1f);
				split_lcd(FALSE);
				
				
			}
		else
			{
				//i2c_write(SLAVE_ADDRESS,(uint8_t *)edid_3840,258);
				CLK_SysTickDelay(30000);
				split_lcd_half(TRUE);				
				hdmi_video_start();
				CLK_SysTickDelay(30000);
				hdmi_video_stop();
				mipi2lvds_1080_single(1,0x1f);
				mipi2lvds_1080_single(2,0x1f);
				
				//status_3d=0;
				
			}
		//CLK_SysTickDelay(30000);
		hdmi_video_start();
		oled_start();
		
		
	
	
}

#else
void hdmi_initedid()
{
	
	//<!-- EDID --> 																									
	buffer[0]=0x85, buffer[1]=0xE0, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x85, buffer[1]=0xE3, buffer[2]=0x00, buffer[3]=0x01,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>	
	//<!-- EDID Data -->																								
	buffer[0]=0x8C, buffer[1]=0x00, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x01, buffer[2]=0xFF,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x02, buffer[2]=0xFF,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x03, buffer[2]=0xFF,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x04, buffer[2]=0xFF,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x05, buffer[2]=0xFF,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x06, buffer[2]=0xFF,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x07, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x08, buffer[2]=0x52,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x09, buffer[2]=0x62,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x0A, buffer[2]=0x88,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x0B, buffer[2]=0x88,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x0C, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x0D, buffer[2]=0x88,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x0E, buffer[2]=0x88,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x0F, buffer[2]=0x88,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x10, buffer[2]=0x1C,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x11, buffer[2]=0x15,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x12, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x13, buffer[2]=0x03,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x14, buffer[2]=0x80,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x15, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x16, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x17, buffer[2]=0x78,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x18, buffer[2]=0x0A,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x19, buffer[2]=0x0D,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x1A, buffer[2]=0xC9,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x1B, buffer[2]=0xA0,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x1C, buffer[2]=0x57,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x1D, buffer[2]=0x47,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x1E, buffer[2]=0x98,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x1F, buffer[2]=0x27,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x20, buffer[2]=0x12,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x21, buffer[2]=0x48,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x22, buffer[2]=0x4C,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x23, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x24, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x25, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x26, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x27, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x28, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x29, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x2A, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x2B, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x2C, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x2D, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x2E, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x2F, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x30, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x31, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x32, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x33, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x34, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x35, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x36, buffer[2]=0x02,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x37, buffer[2]=0x3A,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x38, buffer[2]=0x80,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x39, buffer[2]=0x18,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x3A, buffer[2]=0x71,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x3B, buffer[2]=0x38,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x3C, buffer[2]=0x2D,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x3D, buffer[2]=0x40,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x3E, buffer[2]=0x58,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x3F, buffer[2]=0x2C,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x40, buffer[2]=0x45,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x41, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x42, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x43, buffer[2]=0x38,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x44, buffer[2]=0xF4,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x45, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x46, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x47, buffer[2]=0x1E,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x48, buffer[2]=0x02,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x49, buffer[2]=0x3A,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x4A, buffer[2]=0x80,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x4B, buffer[2]=0x18,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x4C, buffer[2]=0x71,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x4D, buffer[2]=0x38,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x4E, buffer[2]=0x2D,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x4F, buffer[2]=0x40,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x50, buffer[2]=0x58,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x51, buffer[2]=0x2C,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x52, buffer[2]=0x45,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x53, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x54, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x55, buffer[2]=0x38,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x56, buffer[2]=0xF4,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x57, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x58, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x59, buffer[2]=0x1E,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x5A, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x5B, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x5C, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x5D, buffer[2]=0xFC,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x5E, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x5F, buffer[2]=0x48,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x60, buffer[2]=0x69,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x61, buffer[2]=0x67,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x62, buffer[2]=0x68,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x63, buffer[2]=0x67,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x64, buffer[2]=0x6C,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x65, buffer[2]=0x61,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x66, buffer[2]=0x73,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x67, buffer[2]=0x73,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x68, buffer[2]=0x48,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x69, buffer[2]=0x32,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x6A, buffer[2]=0x2D,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x6B, buffer[2]=0x31,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x6C, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x6D, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x6E, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x6F, buffer[2]=0xFD,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x70, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x71, buffer[2]=0x14,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x72, buffer[2]=0x78,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x73, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x74, buffer[2]=0xFF,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x75, buffer[2]=0x1D,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x76, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x77, buffer[2]=0x0A,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x78, buffer[2]=0x20,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x79, buffer[2]=0x20,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x7A, buffer[2]=0x20,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x7B, buffer[2]=0x20,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x7C, buffer[2]=0x20,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x7D, buffer[2]=0x20,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x7E, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x7F, buffer[2]=0x11,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x80, buffer[2]=0x02,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x81, buffer[2]=0x03,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x82, buffer[2]=0x1A,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x83, buffer[2]=0x40,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x84, buffer[2]=0x47,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x85, buffer[2]=0x10,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x86, buffer[2]=0x13,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x87, buffer[2]=0x03,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x88, buffer[2]=0x02,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x89, buffer[2]=0x07,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x8A, buffer[2]=0x06,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x8B, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x8C, buffer[2]=0x23,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x8D, buffer[2]=0x09,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x8E, buffer[2]=0x07,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x8F, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x90, buffer[2]=0x83,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x91, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x92, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x93, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x94, buffer[2]=0x65,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x95, buffer[2]=0x03,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x96, buffer[2]=0x0C,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x97, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x98, buffer[2]=0x10,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x99, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x9A, buffer[2]=0x02,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x9B, buffer[2]=0x3A,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x9C, buffer[2]=0x80,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x9D, buffer[2]=0x18,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x9E, buffer[2]=0x71,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0x9F, buffer[2]=0x38,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xA0, buffer[2]=0x2D,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xA1, buffer[2]=0x40,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xA2, buffer[2]=0x58,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xA3, buffer[2]=0x2C,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xA4, buffer[2]=0x45,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xA5, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xA6, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xA7, buffer[2]=0x38,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xA8, buffer[2]=0xF4,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xA9, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xAA, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xAB, buffer[2]=0x1E,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xAC, buffer[2]=0x02,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xAD, buffer[2]=0x3A,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xAE, buffer[2]=0x80,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xAF, buffer[2]=0x18,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xB0, buffer[2]=0x71,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xB1, buffer[2]=0x38,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xB2, buffer[2]=0x2D,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xB3, buffer[2]=0x40,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xB4, buffer[2]=0x58,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xB5, buffer[2]=0x2C,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xB6, buffer[2]=0x45,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xB7, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xB8, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xB9, buffer[2]=0x38,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xBA, buffer[2]=0xF4,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xBB, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xBC, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xBD, buffer[2]=0x1E,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xBE, buffer[2]=0x02,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xBF, buffer[2]=0x3A,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xC0, buffer[2]=0x80,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xC1, buffer[2]=0x18,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xC2, buffer[2]=0x71,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xC3, buffer[2]=0x38,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xC4, buffer[2]=0x2D,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xC5, buffer[2]=0x40,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xC6, buffer[2]=0x58,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xC7, buffer[2]=0x2C,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xC8, buffer[2]=0x45,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xC9, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xCA, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xCB, buffer[2]=0x38,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xCC, buffer[2]=0xF4,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xCD, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xCE, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xCF, buffer[2]=0x1E,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xD0, buffer[2]=0x02,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xD1, buffer[2]=0x3A,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xD2, buffer[2]=0x80,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xD3, buffer[2]=0x18,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xD4, buffer[2]=0x71,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xD5, buffer[2]=0x38,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xD6, buffer[2]=0x2D,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xD7, buffer[2]=0x40,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xD8, buffer[2]=0x58,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xD9, buffer[2]=0x2C,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xDA, buffer[2]=0x45,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xDB, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xDC, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xDD, buffer[2]=0x38,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xDE, buffer[2]=0xF4,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xDF, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xE0, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xE1, buffer[2]=0x1E,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xE2, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xE3, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xE4, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xE5, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xE6, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xE7, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xE8, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xE9, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xEA, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xEB, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xEC, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xED, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xEE, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xEF, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xF0, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xF1, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xF2, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xF3, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xF4, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xF5, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xF6, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xF7, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xF8, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xF9, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xFA, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xFB, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xFC, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xFD, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xFE, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					
	buffer[0]=0x8C, buffer[1]=0xFF, buffer[2]=0xF4,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					

}
#endif

void hdmi_hdcpsetting()
{

	
	//<!-- HDCP Setting --> 		
	buffer[0]=0x85, buffer[1]=0xEC, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>												  
	buffer[0]=0x85, buffer[1]=0x60, buffer[2]=0x24,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>		
	buffer[0]=0x85, buffer[1]=0x63, buffer[2]=0x11,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>												  
	buffer[0]=0x85, buffer[1]=0x64, buffer[2]=0x0F,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>		
	//<!-- Video Color Format Setting -->																											  
	
	//<!-- HDMI SYSTEM -->																															  
	buffer[0]=0x85, buffer[1]=0x43, buffer[2]=0x02,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>												  
	buffer[0]=0x85, buffer[1]=0x44, buffer[2]=0x10,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>												  
	//<!-- HDMI Audio Setting -->																													  
	buffer[0]=0x86, buffer[1]=0x00, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>												  
	buffer[0]=0x86, buffer[1]=0x02, buffer[2]=0xF3,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>												  
	buffer[0]=0x86, buffer[1]=0x03, buffer[2]=0x02,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>												  
	buffer[0]=0x86, buffer[1]=0x04, buffer[2]=0x0C,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>												  
	buffer[0]=0x86, buffer[1]=0x06, buffer[2]=0x05,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>												  
	buffer[0]=0x86, buffer[1]=0x07, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>												  
	buffer[0]=0x86, buffer[1]=0x52, buffer[2]=0x02,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>												  
	buffer[0]=0x86, buffer[1]=0x71, buffer[2]=0xBA, buffer[3]=0x49, buffer[4]=0x0C, buffer[5]=0x02,i2c_write(SLAVE_ADDRESS,buffer,6);  //</i2c_write> 
	buffer[0]=0x86, buffer[1]=0x75, buffer[2]=0x89, buffer[3]=0xB0, buffer[4]=0xE1, buffer[5]=0x01,i2c_write(SLAVE_ADDRESS,buffer,6);  //</i2c_write> 
	buffer[0]=0x86, buffer[1]=0x80, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>													  
	//<!-- Let HDMI Source start access --> 																										  
	buffer[0]=0x85, buffer[1]=0x4A, buffer[2]=0x01,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>												  

}


uint8_t hdmi_wait_hdmisync()
{
	int count=0;
	//<!-- HDMI Signal Detection -->																					  
	//<!-- Wait until HDMI sync is established -->																		  
	//<!-- By Interrupt   In Interrupt Service Routine. --> 			

		
	//buffer[0]=0x85, buffer[1]=0x20,i2c_write(SLAVE_ADDRESS,buffer,2);	//</i2c_write>	
	i2c_read(SLAVE_ADDRESS,0x8520,buffer,1);
	if(buffer[0]&0x80)
		{
			//return 1;
		}
	//<i2c_read addr="0x0F" count="1" radix="16" /> 																	  
	//<!-- Sequence: Check bit7 of 8x8520 -->																			  
	buffer[0]=0x85, buffer[1]=0x0B, buffer[2]=0xFF,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>					  
	buffer[0]=0x00, buffer[1]=0x14, buffer[2]=0xBF, buffer[3]=0x0F,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>	  
	//<!-- By Polling -->																								  
	//buffer[0]=0x85, buffer[1]=0x20,i2c_write(SLAVE_ADDRESS,buffer,2);	//</i2c_write>		

	while(1)
		{
			i2c_read(SLAVE_ADDRESS,0x8520,buffer,1);
			if(buffer[0]&0x80 )
				{
					i2c_read(SLAVE_ADDRESS,0x8528,buffer,1);
					if(buffer[0]==00||buffer[0]==1)//RGB INTERFACE
						{
							buffer[0]=0x8A, buffer[1]=0x00, buffer[2]=0x02,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>
							buffer[0]=0x8A, buffer[1]=0x01, buffer[2]=0x12,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>
							buffer[0]=0x8A, buffer[1]=0x02, buffer[2]=0x42,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>
							buffer[0]=0x8A, buffer[1]=0x08, buffer[2]=0x30,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>
						}
					else//yuv
						{
							buffer[0]=0x8A, buffer[1]=0x00, buffer[2]=0x00,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>
							buffer[0]=0x8A, buffer[1]=0x01, buffer[2]=0x14,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>
							buffer[0]=0x8A, buffer[1]=0x02, buffer[2]=0x42,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>
							buffer[0]=0x8A, buffer[1]=0x08, buffer[2]=0x11,i2c_write(SLAVE_ADDRESS,buffer,3); //</i2c_write>
						}
					return 1;
				}
			CLK_SysTickDelay(20000);
			// handle USB event
			UsbTransferHandleEvent();

			// update sensor
			if (Timer1IsTrigger()) {
				Timer1ResetFlag();
				UsbTransferHandleSensorUpdate();
			}
			//CLK_SysTickDelay(2000000);
		}
	

	//return 0;
	//<i2c_read addr="0x0F" count="1" radix="16" /> 																	  
	//<!-- Sequence: Check bit7 of 8x8520 -->																			  
	//<!-- Start Video TX -->																							  

}



void hdmi_video_start()
{
//	buffer[0]=0x70, buffer[1]=0x00, buffer[2]=0x0d, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>
//	buffer[0]=0x70, buffer[1]=0x08, buffer[2]=0x2c, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>
//	buffer[0]=0x70, buffer[1]=0x0a, buffer[2]=0x05, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>
//	buffer[0]=0x70, buffer[1]=0x0c, buffer[2]=0x98, buffer[3]=0x08,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>
//	buffer[0]=0x70, buffer[1]=0x0e, buffer[2]=0x65, buffer[3]=0x04,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>
//	buffer[0]=0x70, buffer[1]=0x10, buffer[2]=0x80, buffer[3]=0x07,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>
//	buffer[0]=0x70, buffer[1]=0x12, buffer[2]=0x38, buffer[3]=0x04,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>
//	buffer[0]=0x70, buffer[1]=0x14, buffer[2]=0x0c, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>
//	buffer[0]=0x70, buffer[1]=0x16, buffer[2]=0x29, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>
	

	
	//<!-- Start Video TX -->																														  
									  
	buffer[0]=0x00, buffer[1]=0x06, buffer[2]=0x00, buffer[3]=0x00,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>								  
	//CLK_SysTickDelay(100000);
	//<!-- Command Transmission After Video Start. -->																								  
	buffer[0]=0x01, buffer[1]=0x10, buffer[2]=0x06, buffer[3]=0x00, buffer[4]=0x00, buffer[5]=0x00,i2c_write(SLAVE_ADDRESS,buffer,6);  //</i2c_write> 
	buffer[0]=0x03, buffer[1]=0x10, buffer[2]=0x06, buffer[3]=0x00, buffer[4]=0x00, buffer[5]=0x00,i2c_write(SLAVE_ADDRESS,buffer,6);  //</i2c_write> 
	//CLK_SysTickDelay(100);
	buffer[0]=0x00, buffer[1]=0x04, buffer[2]=0x37, buffer[3]=0x0C,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>
	//<sleep ms="1000" />
	CLK_SysTickDelay(1000);
							  
	//<sleep ms="1" />	
	//CLK_SysTickDelay(1000);
																																					  

}

void hdmi_video_stop()
{

	
	//<!-- Start Video TX -->																														  
	buffer[0]=0x00, buffer[1]=0x04, buffer[2]=0x34, buffer[3]=0x0C,i2c_write(SLAVE_ADDRESS,buffer,4); //</i2c_write>								  
																																					  

}


//void init_hdmi2mipi()
//{
//	hdmi_softrst();
//	
//	hdmi_settxtiming();
//	hdmi_initedid();
//	CLK_SysTickDelay(1000);
//	hdmi_command_trans_init();
//	lcd_init();
//	
//	hdmi_hdcpsetting();
//	lvds_init_all();
//	if(hdmi_wait_hdmisync())
//		{
//			hdmi_video_start();
//		}
//	

//}




void mipi2lvds_1080(uint8_t ch,uint8_t slaveadd)
{
	
	//REM	**************************************************																																	 
	//REM	TC358774/75XBG DSI Basic Parameters.  Following 10 setting should be pefromed in LP mode																							   
	//REM	**************************************************																																	 
	LVDS_write_reg_32(ch,slaveadd,0x013C	,0x000A000C);// PPI_TX_RX_TA  BTA parameters	LP																								 
	LVDS_write_reg_32(ch,slaveadd,0x0114	,0x00000008);// PPI_LPTXTIMCNT	LP																											   
	LVDS_write_reg_32(ch,slaveadd,0x0164	,0x00000009);// PPI_D0S_CLRSIPOCOUNT	LP																										 
	LVDS_write_reg_32(ch,slaveadd,0x0168	,0x00000009);// PPI_D1S_CLRSIPOCOUNT	LP																										 
	LVDS_write_reg_32(ch,slaveadd,0x016C	,0x00000009);// PPI_D2S_CLRSIPOCOUNT	LP																										 
	LVDS_write_reg_32(ch,slaveadd,0x0170	,0x00000009);// PPI_D3S_CLRSIPOCOUNT	LP																										 
	LVDS_write_reg_32(ch,slaveadd,0x0134	,0x0000001F);// PPI_LANEENABLE	LP																											   
	LVDS_write_reg_32(ch,slaveadd,0x0210	,0x0000001F);// DSI_LANEENABLE	LP																											   
	LVDS_write_reg_32(ch,slaveadd,0x0104	,0x00000001);// PPI_SARTPPI LP																												   
	LVDS_write_reg_32(ch,slaveadd,0x0204	,0x00000001);// DSI_SARTPPI LP																												   
																																																   
	//REM	**************************************************																																	 
	//REM	TC358774/75XBG Timing and mode setting																																				 
	//REM	**************************************************																																	 
	LVDS_write_reg_32(ch,slaveadd,0x0450,	0x03F00120);//	VPCTRL	LP or HS	* To use common setting both for TC358764/65 and TC358774/75,setting to reseved bit is added.				
	LVDS_write_reg_32(ch,slaveadd,0x0454,	0x0094002C);//	HTIM1	LP or HS																												   
	LVDS_write_reg_32(ch,slaveadd,0x0458,	0x00580780);//	HTIM2	LP or HS																												   
	LVDS_write_reg_32(ch,slaveadd,0x045C,	0x00240005);//	VTIM1	LP or HS																												   
	LVDS_write_reg_32(ch,slaveadd,0x0460,	0x00040438);//	VTIM2	LP or HS																												   
	LVDS_write_reg_32(ch,slaveadd,0x0464,	0x00000001);//	VFUEN	LP or HS																												   
	LVDS_write_reg_32(ch,slaveadd,0x04A0,	0x00448406);//	LVPHY0	LP or HS																												 
	delay(500); 																																										   
	LVDS_write_reg_32(ch,slaveadd,0x04A0,	0x000048406);//	LVPHY0	LP or HS																												 
	LVDS_write_reg_32(ch,slaveadd,0x0504,	0x000000004);//	SYSRST	LP or HS																												 
	//REM	**************************************************																																	 
	//REM	TC358774/75XBG LVDS Color mapping setting																																			   
	//REM	**************************************************	
	#if 1	// normal mode
//	LVDS_write_reg_32(ch,slaveadd,0x0480,	0x1B1B1B1B);//	LVMX0003	LP or HS																														   
//	LVDS_write_reg_32(ch,slaveadd,0x0484,	0x1B1B1B1B);//	LVMX0407	LP or HS																														   
//	LVDS_write_reg_32(ch,slaveadd,0x0488,	0x1B1B1B1B);//	LVMX0811	LP or HS																														   
//	LVDS_write_reg_32(ch,slaveadd,0x048C,	0x1B1B1B1B);//	LVMX1215	LP or HS																														   
//	LVDS_write_reg_32(ch,slaveadd,0x0490,	0x1B1B1B1B);//	LVMX1619	LP or HS																														   
//	LVDS_write_reg_32(ch,slaveadd,0x0494,	0x1B1B1B1B);//	LVMX2023	LP or HS																														   
//	LVDS_write_reg_32(ch,slaveadd,0x0498,	0x1B1A1918);//	LVMX2427	LP or HS		
	#else	//test mode
	LVDS_write_reg_32(ch,slaveadd,0x0480,	0x1B1B1B1B);//	LVMX0003	LP or HS																														   
	LVDS_write_reg_32(ch,slaveadd,0x0484,	0x1B1B1B1B);//	LVMX0407	LP or HS																														   
	LVDS_write_reg_32(ch,slaveadd,0x0488,	0x1B1B1B1B);//	LVMX0811	LP or HS																														   
	LVDS_write_reg_32(ch,slaveadd,0x048C,	0x1B1B1B1B);//	LVMX1215	LP or HS																														   
	LVDS_write_reg_32(ch,slaveadd,0x0490,	0x1A1A1A1A);//	LVMX1619	LP or HS																														   
	LVDS_write_reg_32(ch,slaveadd,0x0494,	0x1B1A1A1A);//	LVMX2023	LP or HS																														   
	LVDS_write_reg_32(ch,slaveadd,0x0498,	0x1B1A1918);//	LVMX2427	LP or HS	
	#endif
	//REM	**************************************************																																	 
	//REM	TC358774/75XBG LVDS enable																																							 
	//REM	**************************************************																																	 
	LVDS_write_reg_32(ch,slaveadd,0x049C,	0x00000263);	//LVCFG	LP or HS	* To use common setting both for TC358764/65 and TC358774/75,setting to reseved bit is added.								 

}

void mipi2lvds_1080_single(uint8_t ch,uint8_t slaveadd)
{
	
	LVDS_write_reg_32(ch,slaveadd,0x049C,	0x00000260);	//LVCFG	LP or HS	* To use common setting both for TC358764/65 and TC358774/75,setting to reseved bit is added.			
	LVDS_write_reg_32(ch,slaveadd,0x0458,	0x005803c0);//	HTIM2	LP or HS																																		 
	CLK_SysTickDelay(30000);	
	LVDS_write_reg_32(ch,slaveadd,0x049C,	0x00000261);

}

void mipi2lvds_1080_dual(uint8_t ch,uint8_t slaveadd)
{
	
	LVDS_write_reg_32(ch,slaveadd,0x049C,	0x00000260);	//LVCFG	LP or HS	* To use common setting both for TC358764/65 and TC358774/75,setting to reseved bit is added.			
	LVDS_write_reg_32(ch,slaveadd,0x0458,	0x00580780);//	HTIM2	LP or HS																																		 
	CLK_SysTickDelay(30000);	
	LVDS_write_reg_32(ch,slaveadd,0x049C,	0x00000263);

}






void lvds_init_all_1080()
{
	mipi2lvds_1080(1,0x1f);
	mipi2lvds_1080(2,0x1f);

}





